/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Daniel
 */
public class Query_Login {
    
    public static User query_login(String user , String password)
     {       
         String query = "Select user_name , user , user_supervisor , user_rol_ID"
                 + " from users_credentials join users_roles "
                 + " on user_rol = user_rol_ID"
                 + " where user_name = '"+user+"' and password = '"+password+"' ";
       
       User tmp = null;
       
       try 
       {
        Connection con = DBconnection.getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        
        int role = -1;
        int id = -1;
        
        while(rs.next())
          {
          role = rs.getInt("user_rol_ID");    
          switch(role)
             {
              case 2 : id = rs.getInt("user_supervisor"); break;
              case 3 : id = rs.getInt("user"); break;              
          } 
         
          } 
        
         tmp = new User(role , id , user);
        
       }catch(Exception e)  {
           e.printStackTrace();
       } 
       
        
         return tmp;
     } 
    
    public static void delete(String user)
           {
              Query_Studente.delete(user);
              Query_Advisor.delete(user);
              Query_Docente.delete(user);
              //Query_Segreteria_Corsi.delete(user);
              //Query_corsi.delete(user);
    
           } 
            
            
        
    
    
    
    
}
